﻿using System;
using System.Collections.ObjectModel;
using System.Diagnostics;

namespace PerformanceTestsFile
{
    //Somewhere from StackOverflow ...

    public class Benchmark : IDisposable
    {
        private readonly Stopwatch timer = new Stopwatch();
        private readonly string benchmarkName;
        private readonly ObservableCollection<string> _lines;

        public TimeSpan Elapsed
        {
            get { return timer.Elapsed; }
        }

        public Benchmark(string benchmarkName, ObservableCollection<string> lines)
        {
            this.benchmarkName = benchmarkName;
            timer.Start();
            _lines = lines;
        }

        public void Dispose()
        {
            timer.Stop();
            _lines.Add($"{benchmarkName} {timer.Elapsed}");
        }
    }
}
